﻿using Newtonsoft.Json;
using PanhuaWin.NCModel;
using PanhuaWin.WMS2NC888;
using Sunny.UI;
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;

namespace PanhuaWin.工厂.仓库.生产领用
{
    public partial class Form原料卷推送NC : UIPage
    {
        public Form原料卷推送NC()
        {
            InitializeComponent();
        }
        private void Form原料卷推送NC_Load(object sender, EventArgs e)
        {
            uiDatePicker1.Value = DateTime.Now.FirstDayOfMonth();
            uiDatePicker2.Value = DateTime.Now;
        }
        private void uiButton查询_Click(object sender, EventArgs e)
        {
            //Queryable();
            查热卷待出();
        }

        private void 查热卷待出()
        {
            System.Data.DataTable tb1 = GetList();
            if (tb1.Rows.Count > 0)
            {
                this.uiDataGridView清单.AutoGenerateColumns = false;
                this.uiDataGridView清单.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
                this.uiDataGridView清单.DataSource = tb1;
                this.uiDataGridView清单.Refresh();
            }
            else
            {
                this.uiDataGridView清单.DataSource = null;
                this.uiDataGridView清单.Refresh();
            }
        }

        private void Queryable()
        {
            string sql = @"select Bus_StockOutV.guid, StockOutType, Bus_StockOutV.WorkShopCode, Bus_StockOutV.DocCode, DepartCode, CreateID, Creator, CreateDate, ModifyID, Modifier, 
                            ModifyDate, ApproverID, Approver, ApproverDate, Bguid,  RowNumber,  WarehouseCode, StorageLocation, VolumeCode, 
                            VolumeCodeNew, InventoryCode, InventoryName, Size, Thick, Width, Material, Address, Weight, CID, Virtual, OutputSize, 
                            ProductSize, NextWorkType, Remark, Bus_StockOutVolume.IsSendToNC, Bus_StockOutVolume.SendToNCResult, Bus_StockOutVolume.SendToNCDate
                            from Bus_StockOutV
                            left join Bus_StockOutVolume on Bus_StockOutV.guid = Bus_StockOutVolume.guid where 1=1";
            sql += " and CreateDate >= '" + uiDatePicker1.Value.ToString("yyyy-MM-dd") + "'";
            sql += " and CreateDate <= '"+ uiDatePicker2.Value.ToString("yyyy-MM-dd") + "'";
            sql += " and StockOutType = '原料出库'";
          
            if (uiCheckBox包含已发出.Checked)
            {
                
            }
            else
            {
                sql += " and (Bus_StockOutVolume.IsSendToNC is null or Bus_StockOutVolume.IsSendToNC = 'N' OR  Bus_StockOutVolume.IsSendToNC = '')";
            }
            sql += " order by CreateDate";
            DataTable dt = pub.GetDataTable(pub.ConnectionString,sql);
            uiDataGridView清单.DataSource = dt;
            uiDataGridView清单.Refresh();
        }

        private DataTable GetList()
        {
            string sql = @"SELECT  row_number() over(order by  CreateDate) 序号,guid, WorkShopGuid, WorkShopCode, DepartGuid, DepartCode 部门编号, WorkLineCode, WorkLineName 产线名称, WorkDate, RowNumber,
                           Originalsize 热轧规格, Address 产地, VolumeCode , VolumeCodeNew 热轧批号, Weight 重量, OutputSize 轧制规格, ProductSize 成品规格,NextWorkType 去向, Material 材质, StorageLocation 库位, MAC,
                          CreateDate, remark 备注,Approver 发料人 ,ApproverDate 发料时间,Customer 客户,IsSendToNC,SendToNCResult FROM Bus_PlanPickling  where 1=1   ";
            sql += " and CreateDate>='" + this.uiDatePicker1.Value.ToString("yyyy-MM-dd") + "'";
            sql += " and CreateDate<'" + this.uiDatePicker2.Value.AddDays(1).ToString("yyyy-MM-dd") + "'  and  (Approver is not null or Approver <> '')";
            if (this.uiCheckBox包含已发出.Checked)
            {
                //sql += " and VolumeCodeNew not in (select VolumeCodeNew from Bus_StockOutVolume) ";
                sql += " and  (IsSendToNC is not null or IsSendToNC <> '')";
            }
            else
            {
                sql += " and  (IsSendToNC is  null or IsSendToNC = ''  or IsSendToNC = 'N')";
            }
            string WorkShopCode = pub.全局工厂编号;
            sql += " and WorkShopCode='" + WorkShopCode + "'";

            //if (this.uiComboBox材质1.SelectedText != "全部" && this.uiComboBox材质1.SelectedText != "")
            //{
            //    string Material = this.uiComboBox材质1.SelectedText.Trim();
            //    sql += " and Material='" + Material + "'";
            //}
            //if (this.uiCheckBox1.Checked)
            //{
            //    sql += " and WorkLineName='" + this.uiComboBox产线.SelectedText + "'";
            //}

            //if (this.uiComboBox去向.SelectedText != "全部" && this.uiComboBox去向.SelectedText != "")
            //{
            //    string NextWorkType = this.uiComboBox去向.SelectedText.ToString().Trim();
            //    sql += " and NextWorkType='" + NextWorkType + "'";
            //}
            //if (this.uiTextBox热轧规格.Text != "")
            //{
            //    string Originalsize = this.uiTextBox热轧规格.Text.Trim().Replace("--", "");
            //    sql += " and Originalsize='" + Originalsize + "'";
            //}
            //if (this.uiTextBox产地1.Text != "")
            //{
            //    string Address = this.uiTextBox产地1.Text.Trim().Replace("--", "");
            //    sql += " and Address='" + Address + "'";
            //}
            //if (this.uiTextBox成品规格.Text != "")
            //{
            //    string ProductSize = this.uiTextBox成品规格.Text.Trim().Replace("--", "");
            //    sql += " and ProductSize='" + ProductSize + "'";
            //}
            //if (this.uiTextBox轧制规格.Text != "")
            //{
            //    string OutputSize = this.uiTextBox轧制规格.Text.Trim().Replace("--", "");
            //    sql += " and OutputSize='" + OutputSize + "'";
            //}


            DataTable tb = pub.GetDataTable(pub.ConnectionString, sql);
            return tb;
        }

        private void uiButton推送NC_Click(object sender, EventArgs e)
        {
            string logsql = @"insert into Sys_Log( BeginDate, BrowserType, RequestParameter,UserName, User_Id ,UserIP,ServiceIP   )";
            logsql += "values(getdate(),'WinForm','调用NCservice','" + pub.sys_user.UserName + "','" + pub.sys_user.User_Id + "','" + MAC.getIP.getLocalIP() + "','WMS2NC888')";
            pub.ExecuteSql(pub.ConnectionString, logsql);

            if (uiDataGridView清单.Rows != null && uiDataGridView清单.Rows.Count > 0)
            {
                for (int i = 0; i < uiDataGridView清单.Rows.Count; i++)
                {
                    if (uiDataGridView清单.Rows[i].Cells["D选中"].Value != null && (bool)uiDataGridView清单.Rows[i].Cells["D选中"].Value)
                    {
                        string planPicklingGuid = uiDataGridView清单.Rows[i].Cells["Dguid"].Value.ToString();
                        //string bguid = uiDataGridView清单.Rows[i].Cells["CBguid"].Value.ToString();
                        string 热轧批号 = uiDataGridView清单.Rows[i].Cells["D热轧批号"].Value.ToString();
                        NCResponseModel nCResponse = send原来领用ToNC(planPicklingGuid, 热轧批号);
                        //调用成功，改写NC状态  -一单多行
                        //if (nCResponse.state == 0)
                        //{
                        //    //更新出库表
                        //    string sqlUpdate = @"update Bus_StockOutVolume set IsSendToNC = 'Y',SendToNCResult = '" + nCResponse.result + "' ,SendToNCDate = '"
                        //                        + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where guid = '" + guid + "'";
                        //    int r = pub.ExecuteSql(pub.ConnectionString, sqlUpdate, "原料卷入库发送到NC");
                        //    uiDataGridView清单.Rows[i].Cells["CIsSendToNC"].Value = "Y";
                        //    if (r < 1)
                        //    {
                        //        MessageBox.Show("更新成功发送到NC失败");
                        //    }
                        //}
                        //else
                        //{
                        //    string sqlUpdate = @"update Bus_StockOutVolume set IsSendToNC = 'N',SendToNCResult = '" + nCResponse.msg + "' ,SendToNCDate = '"
                        //                        + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where guid = '" + guid + "'";
                        //    uiDataGridView清单.Rows[i].Cells["CIsSendToNC"].Value = "N";
                        //    int r = pub.ExecuteSql(pub.ConnectionString, sqlUpdate, "原料卷入库发送到NC");
                        //    if (r < 1)
                        //    {
                        //        MessageBox.Show("更新失败发送到NC失败");
                        //    }
                        //}
                    }
                   
                }

            }
            查热卷待出();
        }
        private NCResponseModel send原来领用ToNC(string planPicklingGuid,string 热轧批号)
        {
            NCModel.NCResponseModel nCResponse = new NCResponseModel();
            //查询领用出库单头
            string sqlHeader = @"select Bus_StockOutV.guid, StockOutType, Bus_StockOutV.WorkShopCode, Bus_StockOutV.DocCode, DepartCode, CreateID, Creator, CreateDate, ModifyID, Modifier, 
                                ModifyDate, ApproverID, Approver, ApproverDate
                                from Bus_StockOutV left join Bus_StockOutVolume 
                                on Bus_StockOutVolume.guid = Bus_StockOutV.guid
                                where Bus_StockOutV.StockOutType = '原料出库' and Bus_StockOutVolume.VolumeCodeNew = '" + 热轧批号 + "'";
            DataTable dtHeader = pub.GetDataTable(pub.ConnectionString, sqlHeader);
            if (dtHeader != null && dtHeader.Rows.Count > 0)
            {

                //头
                string region = "华中";//地区
                string createdate = DateTime.Parse(dtHeader.Rows[0]["CreateDate"].ToString()).ToString("yyyy-MM-dd");
                string WorkShopCode = dtHeader.Rows[0]["WorkShopCode"].ToString();//公司编号
                string corpName = "";
                string cWhsmanagerCode = dtHeader.Rows[0]["CreateID"].ToString();
                string cbizCode = dtHeader.Rows[0]["CreateID"].ToString(); //业务员编码 
                string wareHouseCode = "F11";
                string cWarehouseName = "";
                string deptCode = dtHeader.Rows[0]["DepartCode"].ToString();
                string deptName = "";
                //查询公司名称 公司编号
                string sqlworkshop = @"SELECT  [WorkShopName]  FROM [Dic_WorkShop] where WorkShopCode = '" + WorkShopCode + "'";
                DataTable dtWorkShop = pub.GetDataTable(pub.ConnectionString, sqlworkshop);
                if (dtWorkShop != null && dtWorkShop.Rows.Count > 0)
                {
                    corpName = dtWorkShop.Rows[0]["WorkShopName"].ToString();
                }

                ////查仓库名称
                //string sqlwareName = "select WarehouseName from Dic_Warehouse where WarehouseCode = '" + wareHouseCode + "'";

                //DataTable dtWareName = pub.GetDataTable(pub.ConnectionString, sqlwareName);
                //if (dtWareName != null && dtWareName.Rows.Count > 0)
                //{
                //    cWarehouseName = dtWareName.Rows[0]["WarehouseName"].ToString();
                //}
                //查部门名称
                string sqlDept = @"SELECT   DepartCode,DepartName FROM      Dic_Depart where DepartCode = '" + deptCode + "' or DepartName = '" + deptCode + "'";
                DataTable dtDept = pub.GetDataTable(pub.ConnectionString, sqlDept);
                if (dtDept != null && dtDept.Rows.Count > 0)
                {
                    //deptName = dtDept.Rows[0]["DepartCode"].ToString().Split('-')[1] +  dtDept.Rows[0]["DepartName"].ToString();
                    deptName = dtDept.Rows[0]["DepartName"].ToString().Trim();
                }
                //NC对象
                MaterialOutBillModel materialOutBillModel = new MaterialOutBillModel();
                materialOutBillModel.region = region;
                materialOutBillModel.createdate = createdate;
                materialOutBillModel.corpName = corpName;
                materialOutBillModel.cwhsmanagercode = cWhsmanagerCode;
                materialOutBillModel.cbizCode = cbizCode;
                //materialOutBillModel.outhouseName = cWarehouseName;
                //materialOutBillModel.cWarehouseName = wareHouseCode;
                materialOutBillModel.remarks = "";
                materialOutBillModel.deptName = deptName.Trim();

                //查表体
                string sqlBody = @"select Bus_StockOutVolume.guid, Bguid, Bus_StockOutVolume.DocCode, RowNumber, Bus_StockOutVolume.WorkShopCode, WarehouseCode, StorageLocation, VolumeCode, 
                                    VolumeCodeNew, InventoryCode, InventoryName, Size, Thick, Width, Material, Address, Weight, CID, Virtual, OutputSize, 
                                    ProductSize, NextWorkType, Remark,Bus_StockOutVolume.IsSendToNC,SendToNCResult
                                    from Bus_StockOutV left join Bus_StockOutVolume 
                                    on Bus_StockOutVolume.guid = Bus_StockOutV.guid
                                    where Bus_StockOutV.StockOutType = '原料出库'
                                    and Bus_StockOutVolume.VolumeCodeNew = '" + 热轧批号 + "'";
                

                DataTable dtBody = pub.GetDataTable(pub.ConnectionString, sqlBody);
                if (dtBody != null && dtBody.Rows.Count > 0)
                {
                    List<MaterialOutBillItemModel> items = new List<MaterialOutBillItemModel>();
                    for (int i = 0; i < dtBody.Rows.Count; i++)
                    {
                        
                        //查入库单的卷信息
                        string stockinVol = @"select Bus_StockInVolume.* from Bus_StockInV
                                    left join Bus_StockInVolume on Bus_StockInVolume.guid = Bus_StockInV.guid
                                    where StockInType = '原料卷入库'
                                    and Bus_StockInVolume.VolumeCodeNew = '" + 热轧批号 + "'";
                        DataTable dtStockinVol = pub.GetDataTable(pub.ConnectionString, stockinVol);

                        //根据原料卷号导入的仓库编号，查仓库名称
                        string sqlwareName = "select WarehouseName from Dic_Warehouse where WarehouseCode = '" + dtStockinVol.Rows[0]["WarehouseCode"].ToString() + "'";

                        DataTable dtWareName = pub.GetDataTable(pub.ConnectionString, sqlwareName);
                        if (dtWareName != null && dtWareName.Rows.Count > 0)
                        {
                            cWarehouseName = dtWareName.Rows[0]["WarehouseName"].ToString();
                        }
                        materialOutBillModel.outhouseName = cWarehouseName;

                        //体
                        string rowNo = dtBody.Rows[i]["Bguid"].ToString(); //明细ID
                        string cinvbascode = dtStockinVol.Rows[0]["InventoryCode"].ToString(); //存货编码
                        string vbatchcode = dtStockinVol.Rows[0]["VolumeCodeNew"].ToString(); //批次号
                        string nnum = dtStockinVol.Rows[0]["Weight"].ToString(); //入库数量
                        string dbilldate = DateTime.Parse(dtHeader.Rows[0]["CreateDate"].ToString()).ToString("yyyy-MM-dd");//入库日期
                        string vuserdef9 = dtStockinVol.Rows[0]["StorageLocation"].ToString();//库位号
                        MaterialOutBillItemModel materialOutBillItemModel = new MaterialOutBillItemModel();
                        materialOutBillItemModel.rowNo = rowNo;
                        materialOutBillItemModel.cinvbascode = cinvbascode;
                        materialOutBillItemModel.vbatchcode = vbatchcode;
                        materialOutBillItemModel.nnum = nnum;
                        materialOutBillItemModel.dbilldate = dbilldate;
                        materialOutBillItemModel.vuserdef9 = vuserdef9;
                        materialOutBillItemModel.vfree1 = "";//颜色
                        materialOutBillItemModel.vfree2 = dtStockinVol.Rows[0]["Material"].ToString(); //长度
                            materialOutBillItemModel.vfree3 = dtStockinVol.Rows[0]["Address"].ToString();//产地

                        materialOutBillItemModel.vfree4 = "";//表面处理
                        materialOutBillItemModel.vfree5 = "";//表面厚度
                        materialOutBillItemModel.pk_defdoc11 = "";//状态(BDZ)
                        materialOutBillItemModel.pk_defdoc12 = "";//卷径
                        materialOutBillItemModel.vnotebody = "";//备注
                        materialOutBillItemModel.vuserdef8 = "";//等级
                        materialOutBillItemModel.vuserdef10 = "";//次级库位
                        materialOutBillItemModel.pk_defdoc13 = "";//船名

                        items.Add(materialOutBillItemModel);
                    }
                    materialOutBillModel.items = items;
                }

                string jsonStr = JsonConvert.SerializeObject(materialOutBillModel);
                ExternalSystemToNcItfPortTypeClient client = new ExternalSystemToNcItfPortTypeClient();
                string responseStr = client.materialOutBill(jsonStr);
                nCResponse = JsonConvert.DeserializeObject<NCModel.NCResponseModel>(responseStr);
                ////调用成功，改写NC状态
                if (nCResponse.state == 0)
                {
                    //更新出库表行的状态
                    string sqlUpdate = @"update Bus_StockOutVolume set IsSendToNC = 'Y',SendToNCResult = '" + nCResponse.result + "' ,SendToNCDate = '"
                                        + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where Bguid = '" + dtBody.Rows[0]["Bguid"].ToString() + "' ;";
                    sqlUpdate += @"update Bus_PlanPickling set IsSendToNC = 'Y',SendToNCResult = '"+ nCResponse.result + "',SendToNCDate = '"
                                    + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where VolumeCodeNew = '" + 热轧批号 + "';";
                    int r = pub.ExecuteSql(pub.ConnectionString, sqlUpdate, "原料卷入库发送到NC");
                    if (r < 1)
                    {
                        MessageBox.Show("更新成功发送到NC失败");
                    }
                }
                else
                {
                    string sqlUpdate = "";
                    if (nCResponse.msg.Contains("已经存在"))
                    {
                        sqlUpdate = @"update Bus_StockOutVolume set IsSendToNC = 'Y'  where Bguid = '" + dtBody.Rows[0]["Bguid"].ToString() + "' ;";
                        sqlUpdate += @"update Bus_PlanPickling set IsSendToNC = 'Y'  where VolumeCodeNew = '" + 热轧批号 + "';";
                    }
                    else
                    {
                         sqlUpdate = @"update Bus_StockOutVolume set IsSendToNC = 'N',SendToNCResult = '" + nCResponse.msg + "' ,SendToNCDate = '"
                                     + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where Bguid = '" + dtBody.Rows[0]["Bguid"].ToString() + "' ;";
                        sqlUpdate += @"update Bus_PlanPickling set IsSendToNC = 'N',SendToNCResult = '" + nCResponse.msg + "',SendToNCDate = '"
                                       + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where VolumeCodeNew = '" + 热轧批号 + "';";
                    }
                 
                    int r = pub.ExecuteSql(pub.ConnectionString, sqlUpdate, "原料卷入库发送到NC");
                    if (r < 1)
                    {
                        MessageBox.Show("更新失败发送到NC失败");
                    }
                }
            }
            return nCResponse;
        }
        private NCResponseModel send原来领用ToNC(string guid)
        {
            NCModel.NCResponseModel nCResponse = new NCResponseModel();
            //查询领用出库单
            string sqlHeader = @"SELECT  guid, StockOutType, WorkShopCode, DocCode, DepartCode, CreateID, Creator, CreateDate, ModifyID, Modifier, 
                           ModifyDate, ApproverID, Approver, ApproverDate, IsSendToNC, SendToNCDate
                            FROM      Bus_StockOutV where guid = '" + guid + "'";
            DataTable dtHeader = pub.GetDataTable(pub.ConnectionString, sqlHeader);
            if (dtHeader != null && dtHeader.Rows.Count > 0)
            {

                //头
                string region = "华中";//地区
                string createdate = DateTime.Parse(dtHeader.Rows[0]["CreateDate"].ToString()).ToString("yyyy-MM-dd");
                string WorkShopCode = dtHeader.Rows[0]["WorkShopCode"].ToString();//公司编号
                string corpName = "";
                string cWhsmanagerCode = dtHeader.Rows[0]["CreateID"].ToString();
                string cbizCode = dtHeader.Rows[0]["CreateID"].ToString(); //业务员编码 
                string wareHouseCode = "F11";
                string cWarehouseName = "";
                string deptCode = dtHeader.Rows[0]["DepartCode"].ToString();
                string deptName = "";
                //查询公司名称 公司编号
                string sqlworkshop = @"SELECT  [WorkShopName]  FROM [Dic_WorkShop] where WorkShopCode = '" + WorkShopCode + "'";
                DataTable dtWorkShop = pub.GetDataTable(pub.ConnectionString, sqlworkshop);
                if (dtWorkShop != null && dtWorkShop.Rows.Count > 0)
                {
                    corpName = dtWorkShop.Rows[0]["WorkShopName"].ToString();
                }

                //查仓库名称
                string sqlwareName = "select WarehouseName from Dic_Warehouse where WarehouseCode = '" + wareHouseCode + "'";

                DataTable dtWareName = pub.GetDataTable(pub.ConnectionString, sqlwareName);
                if (dtWareName != null && dtWareName.Rows.Count > 0)
                {
                    cWarehouseName = dtWareName.Rows[0]["WarehouseName"].ToString();
                }
                //查部门名称
                string sqlDept = @"SELECT   DepartCode,DepartName FROM      Dic_Depart where DepartCode = '" + deptCode + "' or DepartName = '"+ deptCode + "'";
                DataTable dtDept = pub.GetDataTable(pub.ConnectionString, sqlDept);
                if (dtDept != null && dtDept.Rows.Count > 0) 
                {
                    //deptName = dtDept.Rows[0]["DepartCode"].ToString().Split('-')[1] +  dtDept.Rows[0]["DepartName"].ToString();
                    deptName = dtDept.Rows[0]["DepartName"].ToString().Trim();
                }
                //NC对象
                MaterialOutBillModel materialOutBillModel = new MaterialOutBillModel();
                materialOutBillModel.region = region;
                materialOutBillModel.createdate = createdate;
                materialOutBillModel.corpName = corpName;
                materialOutBillModel.cwhsmanagercode = cWhsmanagerCode;
                materialOutBillModel.cbizCode = cbizCode;
                materialOutBillModel.outhouseName = cWarehouseName;
                //materialOutBillModel.cWarehouseName = wareHouseCode;
                materialOutBillModel.remarks = "";
                materialOutBillModel.deptName = deptName.Trim();

                //查表体
                string sqlBody = @"SELECT   guid, Bguid, DocCode, RowNumber, WorkShopCode, WarehouseCode, StorageLocation, VolumeCode, 
                               VolumeCodeNew, InventoryCode, InventoryName, Size, Thick, Width, Material, Address, Weight, CID, Virtual, OutputSize, 
                               ProductSize, NextWorkType, Remark,IsSendToNC,SendToNCResult
                                FROM Bus_StockOutVolume where guid = '" + guid + "'";
                DataTable dtBody = pub.GetDataTable(pub.ConnectionString, sqlBody);
                if (dtBody != null && dtBody.Rows.Count > 0)
                {
                    List<MaterialOutBillItemModel> items = new List<MaterialOutBillItemModel>();
                    for (int i = 0; i < dtBody.Rows.Count; i++)
                    {
                        //体
                        string rowNo = dtBody.Rows[i]["Bguid"].ToString(); //明细ID
                        string cinvbascode = dtBody.Rows[i]["InventoryCode"].ToString(); //存货编码
                        string vbatchcode = dtBody.Rows[i]["VolumeCodeNew"].ToString(); //批次号
                        string nnum = dtBody.Rows[i]["Weight"].ToString(); //入库数量
                        string dbilldate = DateTime.Parse(dtHeader.Rows[0]["CreateDate"].ToString()).ToString("yyyy-MM-dd");//入库日期
                        string vuserdef9 = dtBody.Rows[i]["StorageLocation"].ToString();//库位号
                        MaterialOutBillItemModel materialOutBillItemModel = new MaterialOutBillItemModel();
                        materialOutBillItemModel.rowNo = rowNo;
                        materialOutBillItemModel.cinvbascode = cinvbascode;
                        materialOutBillItemModel.vbatchcode = vbatchcode;
                        materialOutBillItemModel.nnum = nnum;
                        materialOutBillItemModel.dbilldate = dbilldate;
                        materialOutBillItemModel.vuserdef9 = vuserdef9;
                        materialOutBillItemModel.vfree1 = "";//颜色
                        materialOutBillItemModel.vfree2 = dtBody.Rows[i]["Material"].ToString(); //长度
                        materialOutBillItemModel.vfree3 = dtBody.Rows[i]["Address"].ToString();//产地
                        materialOutBillItemModel.vfree4 = "";//表面处理
                        materialOutBillItemModel.vfree5 = "";//表面厚度
                        materialOutBillItemModel.pk_defdoc11 = "";//状态(BDZ)
                        materialOutBillItemModel.pk_defdoc12 = "";//卷径
                        materialOutBillItemModel.vnotebody = "";//备注
                        materialOutBillItemModel.vuserdef8 = "";//等级
                        materialOutBillItemModel.vuserdef10 = "";//次级库位
                        materialOutBillItemModel.pk_defdoc13 = "";//船名

                        items.Add(materialOutBillItemModel);
                    }
                    materialOutBillModel.items = items;
                }
               
                string jsonStr = JsonConvert.SerializeObject(materialOutBillModel);
                ExternalSystemToNcItfPortTypeClient client = new ExternalSystemToNcItfPortTypeClient();
                string responseStr = client.materialOutBill(jsonStr);
                nCResponse = JsonConvert.DeserializeObject<NCModel.NCResponseModel>(responseStr);
                ////调用成功，改写NC状态
                //if (nCResponse.state == 0)
                //{
                //    //更新出库表
                //    string sqlUpdate = @"update Bus_StockOutVolume set IsSendToNC = 'Y',SendToNCResult = '" + nCResponse.result + "' ,SendToNCDate = '"
                //                        + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where guid = '" + guid + "'";
                //    int r = pub.ExecuteSql(pub.ConnectionString, sqlUpdate, "原料卷入库发送到NC");
                //    if (r < 1)
                //    {
                //        MessageBox.Show("更新成功发送到NC失败");
                //    }
                //}
                //else
                //{
                //    string sqlUpdate = @"update Bus_StockOutVolume set IsSendToNC = 'N',SendToNCResult = '" + nCResponse.msg + "' ,SendToNCDate = '"
                //                        + DateTime.Now.ToString("yyyy-MM-dd HH:mm:ss") + "' where guid = '" + guid + "'";
                //    int r = pub.ExecuteSql(pub.ConnectionString, sqlUpdate, "原料卷入库发送到NC");
                //    if (r < 1)
                //    {
                //        MessageBox.Show("更新失败发送到NC失败");
                //    }
                //}
            }
            return nCResponse;
        }

        private void uiCheckBox包含已发出_CheckedChanged(object sender, EventArgs e)
        {

        }

        private void uiButton全选_Click(object sender, EventArgs e)
        {
            if (uiDataGridView清单.Rows != null && uiDataGridView清单.Rows.Count > 0)
            {
                for (int i = 0; i < uiDataGridView清单.Rows.Count; i++)
                {
                    uiDataGridView清单.Rows[i].Cells["D选中"].Value = true;
                }
            }
        }
                    
    }
}
